import {
	defineStore
} from 'pinia'
import {
	getFeedbackTypeList,
	reqQuestionCollect,
	reqSubmitFeedback,
	reqSubmitQuestion
} from '@/service/modules/test-question.js'

export const useTestQuestionStore = defineStore('test-question', {
	state: () => ({
		// 题库
		questionList: [],
		// 当前展示的题目索引 
		currentQuestionIndex: 0,
		// 当前模式flase 答题， true查看解析。
		isReviewing: false,
		// 提交答题前保存用户的答案，无论对错
		questionAnswer: [],
		// 提交答案前保存答案是对还是错
		isCorrectList: [],
		// 题目反馈类型
		feedbackTypeList: [],
	}),
	actions: {
		// 提交答题
		async reqSubmitQuestionAction(data) {
			await reqSubmitQuestion(data)
			// 将用户选的答案清空
			this.questionAnswer = []
		},
		// 获取题目反馈类型
		async getFeedbackTypeListAction() {
			const res = await getFeedbackTypeList()
			this.feedbackTypeList = res.data
		},
		// 提交题目反馈
		async submitFeedbackAction(data) {
			const res = await reqSubmitFeedback(data)
		},
		// 收藏与取消收藏
		async reqQuestionCollectAction(data) {
			const res = await reqQuestionCollect(data)
			// 更改题目收藏或者取消收藏的状态
			this.questionList[this.currentQuestionIndex].isCollect = res.data
		}
	}
})